package com.zut.hospital.controller.examination;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zut.hospital.entity.examination.Student;
import com.zut.hospital.service.examination.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jackson.JsonObjectDeserializer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @PackageName:com.zut.hospital.controller.examination
 * @Date:2019/7/9 21:39
 * @Author: zsy
 */
@Controller
@ResponseBody
public class ResultController {
    @Autowired
    ResultService resultService;

    @PostMapping("/updateResult")
    public void updateResult(@RequestBody String data) {
        Integer id = Integer.parseInt(JSONObject.parseObject(data).getString("id"));
        String value = JSONObject.parseObject(data).getString("value");
        System.out.println(id + "---" + value);
        resultService.UpdateResult(id, value);
    }

    @PostMapping("/deleteResult")
    public void deleteResult(@RequestBody String data) {
        Integer id = Integer.parseInt(JSONObject.parseObject(data).getString("id"));
        System.out.println(id + "---");
        resultService.DeleteResult(id);
    }

    @PostMapping("/addStudent")
    public void addStudent(@RequestBody String data) {
//        Integer id = Integer.parseInt(JSONObject.parseObject(data).getString("id"));
        String num = JSONObject.parseObject(data).getString("num");
        String name = JSONObject.parseObject(data).getString("name");
        Integer age = Integer.parseInt(JSONObject.parseObject(data).getString("age"));
        Integer sex = Integer.parseInt(JSONObject.parseObject(data).getString("sex"));
        String nation = JSONObject.parseObject(data).getString("nation");
        String contact = JSONObject.parseObject(data).getString("contact");
        Integer deptId = Integer.parseInt(JSONObject.parseObject(data).getString("deptId"));
        String remark = JSONObject.parseObject(data).getString("remark");

        Student student = new Student();
        student.setStuNum(num);
        student.setStuName(name);
        student.setStuAge(age);
        student.setStuSex(sex);
        student.setStuNation(nation);
        student.setStuContactInfo(contact);
        student.setStuDepartId(deptId);
        student.setStuRemark(remark);
        resultService.addStudent(student);
    }

    @GetMapping("/allStudent")
    public String allStudent(){
        return resultService.allStudent();
    }
}
